package IOStream.SerializationStream;

import java.io.*;
import java.util.ArrayList;

/**
 * ClassName:Dome004
 * Package:IOStream.SerializationStream
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/3/3-20:23
 * @Version:v1.0
 */
public class Dome004 {
    /*需求
     * 将多个自定义对象序列化到文件中,但是由于对象的个数不确定,反序列化流该如何读取*/
    public static void main(String[] args) throws IOException {
        //序列化多个对象
        Student001 stu1 = new Student001("zhansgan", 25, "山圩");
        Student001 stu2 = new Student001("lisi", 23, "山东");
        Student001 stu3 = new Student001("wnagwu", 26, "河北");
        ArrayList<Student001> list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:\\aaa\\a.txt"));
//        oos.writeObject(stu1);
//        oos.writeObject(stu2);
//        oos.writeObject(stu3);
        oos.writeObject(list);
        oos.close();
    }
}
